package yjl.spec.edu.week11_class023;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import yjl.spec.edu.week11_class023.R;

public class threeActivity extends AppCompatActivity {

    private List<Three> ThreeList = new ArrayList<Three>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_three);
        initThree();
        //得到控件
        RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        //设置布局管理器
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);

        linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //瀑布流
//        StaggeredGridLayoutManager layoutManager = new
//                StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(linearLayoutManager);
        //设置适配器
        ThreeAdapter adapter = new ThreeAdapter(ThreeList);
        recyclerView.setAdapter(adapter);
    }

    private void initThree(){
        for (int i = 0; i < 4; i++) {
            Three Three1 = new Three(R.drawable.irongbe5,"x x x x");
            ThreeList.add(Three1);
            Three Three2 = new Three(R.drawable.irongbe6,"x x x x");
            ThreeList.add(Three2);
            Three Three3 = new Three(R.drawable.irongbe4,"x x x x");
            ThreeList.add(Three3);
            Three Three4 = new Three(R.drawable.irongbe3,"x x x x");
            ThreeList.add(Three4);
            Three Three5 = new Three(R.drawable.irongbe5,"x x x x");
            ThreeList.add(Three5);
        }
    }

    private String getRandomLengthName(String name) {
        Random random = new Random();
        int length = random.nextInt(20) + 1;
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < length; i++) {
            builder.append(name);
        }
        return builder.toString();
    }
}
